/*
 * acooly.cn Inc.
 * Copyright (c) 2016 All Rights Reserved.
 * create by zhangpu 
 * date:2016年4月30日
 *
 */
package com.acooly.module.openapi.client.api.util;

import com.acooly.core.utils.Money;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Date;
import java.util.Map;

/**
 * Java 数据类型判断处理相关工具类
 * 
 * @author zhangpu
 */
public class ApiTypes {

	public static boolean isCollection(Field field) {
		return Collection.class.isAssignableFrom(field.getType()) || field.getType().isArray();
	}

	public static boolean isCollection(Class<?> clazz) {
		return Collection.class.isAssignableFrom(clazz) || clazz.isArray();
	}

	public static boolean isMap(Field field) {
		return Map.class.isAssignableFrom(field.getType());
	}

	public static boolean isMoney(Field field) {
		return Money.class.isAssignableFrom(field.getType());
	}

	public static boolean isNumber(Field field) {
		return isNumber(field.getType());
	}

	public static boolean isNumber(Class<?> clazz) {
		return Number.class.isAssignableFrom(clazz)
				|| (clazz.isPrimitive() && "long,int,byte,short".contains(clazz.toString()));
	}

	public static boolean isString(Field field) {
		return isString(field.getType());
	}

	public static boolean isSimpleType(Class<?> clazz) {
		return isString(clazz) || isNumber(clazz);
	}

	public static boolean isString(Class<?> clazz) {
		return String.class.isAssignableFrom(clazz) || Character.class.isAssignableFrom(clazz)
				|| Date.class.isAssignableFrom(clazz) || Boolean.class.isAssignableFrom(clazz) || clazz.isEnum()
				|| (clazz.isPrimitive() && "boolean,char".contains(clazz.toString()));
	}
}
